package com.wty.schedule.quartzSchedule;

import com.wty.schedule.quartzSchedule.jobs.HelloJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class Test {

    public static void main(String args[]) throws SchedulerException {


//        Scheduler scheduler=StdSchedulerFactory.getDefaultScheduler();


        SchedulerFactory schedulerFactory=new StdSchedulerFactory();
        Scheduler scheduler=schedulerFactory.getScheduler();



        //定义trigger
        SimpleTrigger trigger=TriggerBuilder
                .newTrigger()
                .withIdentity("myTrigger","wty")
                .startNow()
                .withSchedule(SimpleScheduleBuilder
                        .simpleSchedule()
                        .withIntervalInSeconds(1)
                        .repeatForever()).build();

        JobDataMap jobDataMap=new JobDataMap();
        jobDataMap.put("name","lyc");
        jobDataMap.put("age","21");


        //定义jobDetail
        JobDetail jobDetail=JobBuilder.newJob(HelloJob.class)
                .withIdentity("myJob","wty")
//                .usingJobData("name","王腾宇")
//                .usingJobData("age","23")
                .usingJobData(jobDataMap)
                .build();

        scheduler.scheduleJob(jobDetail,trigger);
        scheduler.start();

    }
}
